London Class 10 - Andrius Isin - JS1 - Week 4#232
London Class 10 - Andrius Isin - JS1 - Week 4#232AndriusIsin wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
| // let longNameThatStartsWithA = names.find((element) => { | ||
| // return element.length > 7 && element.startsWith("A"); | ||
| // }); | ||
|
|
There was a problem hiding this comment.
I really like the "startsWith" method you used. Nice! but can you think of another way of checking the second condition without using any method?
| let student = students[indexes[0]]; | ||
| let mentor = mentors[indexes[1]]; | ||
| return [student, mentor]; | ||
| if (indexes !== null) { |
There was a problem hiding this comment.
Your condition works fine, so well done for that! but the aim of this exercise is using some() method on pairsByIndex array. Could you think of using some() instead of line 19.
| console.log("Fizz"); | ||
| } else if (number % 5 === 0) { | ||
| console.log("Buzz"); | ||
| } else { |
There was a problem hiding this comment.
Please read the instruction again, Andrius. There are 3 conditions. You have successfully done first and second condetions but could you add the last condition as well and print "FizzBuzz" when needed.
Also, it's a good practice if in the future you could use ternary operator instead of if else chaining.
| arr[0] = arr[0].toUpperCase(); | ||
| return arr.join(""); | ||
| } | ||
|
|
| .replace(/day/g, "night") | ||
| .replace(/great/g, "brilliant") | ||
| .replace(/10/g, "100000"); | ||
| console.log(result); |
There was a problem hiding this comment.
Is there any specific reason that you used regular expression?
|
|
||
| function remove() { | ||
| function remove(array, index) { | ||
| return array.filter((element, i) => i !== index); |
There was a problem hiding this comment.
This could pass your tests but it isn't very efficient. Imagine if you have a lenghthy array, looping through isn't efficient here. I recommend using methods like slice and concat
| number = 100; | ||
| } | ||
| return `${Math.round(number * 100) / 100}%`; | ||
| }); |
There was a problem hiding this comment.
This function doesn't pass the test and returns undefined.
| function formatPercentage() { | ||
| function formatPercentage(numbers) { | ||
| return numbers.map((number) => { | ||
| if (number > 100) { |
There was a problem hiding this comment.
The instruction is saying if number >= 100 then return "100%". Please amend your if statement
| function formatPercentage(numbers) { | ||
| return numbers.map((number) => { | ||
| if (number > 100) { | ||
| number = 100; |
There was a problem hiding this comment.
This bit isn't right. Can you think why? You are looping through array of numbers and then reassigning 100 to each element in return.
| return "Bush is safe to eat from"; | ||
| } else { | ||
| return "Toxic! Leave bush alone!"; | ||
| } |
There was a problem hiding this comment.
Nice one!
Two things to do if you're interested in learning more!
1- using some() and every() method together as the instruction says
2- when you have if else statement you can remove else, and just return what is supposed to be in else. Please research about it. It cleans up your code!
| function getSettlers() {} | ||
| function getSettlers(voyagers) { | ||
| return voyagers.filter( | ||
| (family) => family.startsWith("A") && family.includes("family") |
There was a problem hiding this comment.
Again startsWith is really handy here, but there's another simple way to get the first index of word and see if it is equal to "A"
| .filter((student) => student[1] >= 8) | ||
| .map((student) => student[0]); | ||
| } | ||
|
|
| return locations | ||
| .filter((location) => location.includes(transportMode)) | ||
| .map((location) => location[0]); | ||
| } |
There was a problem hiding this comment.
This is fine Andrius, you have already defined a funcition above called getLocationName, can you think how you can use this function in line 133?
|
Hey Andrius, really well done for finishing this coursework, it wasn't mandatory though! Please read the comments and I'm happy to discuss them if it's not clear |
No description provided.